package com.yj.account.controller;

import com.yj.account.service.AccountService;
import com.yj.common.responses.TerminalResponse;
import com.yj.oa.entity.system.OAUserInfo;
import com.yj.oa.service.OAInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Copyright 2017 (C) Yunjian-VC
 * Created on : 2017/12/12
 * Author     : Unbelievable9
 **/
@Api(tags = "易煤可视化-个人页面")
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    AccountService accountService;

    @Autowired
    OAInfoService oaInfoService;

    @ApiOperation("获取用户业务信息")
    @GetMapping("/info")
    @ResponseBody
    public TerminalResponse<Object> info(@RequestHeader String token) {
        TerminalResponse<Object> terminalResponse;

        try {
            OAUserInfo oaUserInfo = oaInfoService.getOAUserByToken(token);

            if (oaUserInfo != null) {
                Map<String, Object> infoMap = accountService.getContractInfoByUser(oaUserInfo);

                terminalResponse = new TerminalResponse<>(true, "获取用户业务信息成功", infoMap);
            } else {
                terminalResponse = new TerminalResponse<>(false, "用户信息不存在", null);
            }
        } catch (Exception e) {
            e.printStackTrace();

            terminalResponse = new TerminalResponse<>(false, "获取用户业务信息失败", null);
        }

        return terminalResponse;
    }
}
